using System;
using Gtk;
using Gdk;
using GLib;
using Atk;

namespace PingPong.Generic.ExtensionMethods
{

	public static class GtkExtensions
	{
		/// <summary>
		/// Gets the clipboard text.
		/// </summary>
		/// <returns>The clipboard text.</returns>
		/// <param name="widget">Widget.</param>
		public static string GetClipboardText(this Widget widget)
		{
			Clipboard cl = widget.GetClipboard(Atom.Intern("CLIPBOARD",false));
			return cl.WaitForText();
		}

		/// <summary>
		/// Sets the clipboard text.
		/// </summary>
		/// <param name="widget">Widget.</param>
		/// <param name="text">Text.</param>
		public static void SetClipboardText(this Widget widget, string text)
		{
			Clipboard cl = widget.GetClipboard(Atom.Intern("CLIPBOARD",false));
			cl.Text = text;
		}

		/// <summary>
		/// Sets the clipboard text, ignoring blank or null values.
		/// </summary>
		/// <param name="widget">Widget.</param>
		/// <param name="text">Text.</param>
		public static void SetClipboardTextIgnoreBlankOrNull(this Widget widget, string text)
		{
			if(string.IsNullOrEmpty(text))
			{
				return;
			}

			SetClipboardText(widget,text);
		}
	}
}

